package seqlist.leetcode;

public class Nun142 {
    public ListNode detectCycle(ListNode head) {
        ListNode fast=head;
        ListNode low=head;
        while ( fast != null && fast.next != null){
            fast=fast.next.next;
            low=low.next;
            if (fast==low){
                   ListNode third=head;
                   while (third!=low){
                       low=low.next;
                       third=third.next;
                   }
                   return low;
            }
        }
        return null;
    }
}
